#ifndef __CNODE_H__
#define __CNODE_H__

//---------------------------------------------------------------------------//
// CNode
//---------------------------------------------------------------------------//
#include <vector>
#include <string>

class CNode{
private:
  // Environnement
  double m_d_x,m_d_y;  // Position du noeud
  std::vector <CNode *> m_vpN_neighbours; // Voisins directs
  std::vector <double>  m_vpD_distNeighbours; // Distance voisins directs

  // Noeud
  double m_d_charge;  // Charge de travail du noeud, influence la vitesse de parcours


  // Affichage
  double m_d_radius;   // Rayon

public:
	std::string m_str_name; // Identifiant du noeud
  int id;
  static int sid;
  int in[2];  // Pipe de communication avec le programme tcl/tk
  int out[2];  // Pipe de communication avec le programme tcl/tk

  //---------------------------------------------------------------------------
  // Constructeur
  CNode(double p_d_x, double p_d_y, const char* p_sz_name, double p_d_radius = 8):
  m_d_x(p_d_x),
  m_d_y(p_d_y){
    m_d_charge = 0;
    m_d_radius = p_d_radius;
    m_str_name = p_sz_name;
    id = sid++;
  }

  //---------------------------------------------------------------------------
  // Vide les voisins
  void clearNeighbours(){
    m_vpN_neighbours.clear();
    m_vpD_distNeighbours.clear();
  }

  //---------------------------------------------------------------------------
  // Ajoute un voisin
  void addNeighbour(CNode *p_pN_neigh, double p_d_dist){
    m_vpN_neighbours.push_back(p_pN_neigh);
    m_vpD_distNeighbours.push_back(p_d_dist);
  }

  //---------------------------------------------------------------------------
  // Nombre de voisins
  int nbNeighbours(){return m_vpN_neighbours.size();}

  //---------------------------------------------------------------------------
  // Recupere un voisin
  CNode *getNeighbour(int p_i_indNeigh){
    if(p_i_indNeigh<m_vpN_neighbours.size()){
      return m_vpN_neighbours[p_i_indNeigh];
    }else{
      return NULL;
    }
  }
  
  double getNeighbourDist(int p_i_indNeigh){
	
	      if(p_i_indNeigh<m_vpD_distNeighbours.size()){
      return m_vpD_distNeighbours[p_i_indNeigh];
    }else{
      return 0;
    }
  }

  //---------------------------------------------------------------------------
  // Accesseurs
  double getRadius(){return m_d_radius+m_d_charge;}

  void setX(double p_d_x){m_d_x=p_d_x;}
  void setY(double p_d_y){m_d_y=p_d_y;}
  double getX(){return m_d_x;}
  double getY(){return m_d_y;}

  void setName(const char *p_sz_name){m_str_name = p_sz_name;}
  char* getName(){return (char *)m_str_name.c_str();}

  void addCharge(double p_d_charge){
    if(m_d_charge+p_d_charge<0){m_d_charge=0;}
    else{m_d_charge = p_d_charge;}
  }
  void setCharge(double p_d_charge){
    m_d_charge = p_d_charge;
  }
  double getCharge(){return m_d_charge;}
};

#endif //  __CNODE_H__
